/**
 * 列表初始化
 */
var DengJiPar = {
    id: "DengJiTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
DengJiPar.initColumn = function () {
    return [
        {title:'选择项',field: 'selectItem', radio: true},
        {title: '标题', field: 'orderNo', visible: true, align: 'center', valign: 'middle'},
        {title: '返佣比例', field: 'orderNo', visible: true, align: 'center', valign: 'middle'},
        {title: '奖励积分比例', field: 'orderType', visible: true, align: 'center', valign: 'middle'},
        {title: '等级序号', field: 'orderType', visible: true, align: 'center', valign: 'middle'},
        {title: '等级有效期', field: 'orderType', visible: true, align: 'center', valign: 'middle'},
        {title: '佣金门槛', field: 'orderType', visible: true, align: 'center', valign: 'middle'},
        {title: '关联的会员卡', field: 'orderType', visible: true, align: 'center', valign: 'middle'},
        {title:"操作",field:'Button',events:operateEvents,formatter:DengJiPar.AddFunction}
    ];
};

DengJiPar.AddFunction = function(value,row,index){
    return [
        '<button id="unConfineMember" type="button" class="btn btn-primary">编辑</button>'
    ].join("");
}

window.operateEvents = {
    'click #confineMember':function (e,value,row,index) {
        DisMemberInfo.confineMembers(1,row['disUserId']);
    },
    'click #unConfineMember':function (e,value,row,index) {
        DisMemberInfo.confineMembers(0,row['disUserId']);
    },
}


/**
 * 点击添加按钮
 */
DengJiPar.openAddDengJiParam = function () {
    var index = layer.open({
        type: 2,
        title: '添加等级',
        area: ['700px', '700px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/dengjilist/dengji_add'
    });
    this.layerIndex = index;
};

/**
 * 检查是否选中
 */
DengJiPar.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        DengJiPar.seItem = selected[0];
        return true;
    }
};

/**
 * 查询列表
 */
DengJiPar.search = function () {
    //带参查询
    DengJiPar.table.refresh({query: DengJiPar.formParams()});
};

//表单参数
DengJiPar.formParams = function() {
    var queryData = {};
    queryData['id'] = $("#id").val();
    queryData['userId'] = $("#userId").val();
    queryData['beginTime'] = $("#beginTime").val();
    queryData['endTime'] = $("#endTime").val();
    return queryData;
}

//在整个页面加载的时候
$(function () {
    //获取列表数据
    var defaultColunms = DengJiPar.initColumn();
    var table = new BSTable(DengJiPar.id, "/tixianshezhi/list", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(DengJiPar.formParams());
    DengJiPar.table = table.init();
});
